package edu.xhu.video.service.impl;

import edu.xhu.model.common.dtos.ResponseResult;
import edu.xhu.model.common.enums.AppHttpCodeEnum;
import edu.xhu.video.mapper.BiliVideoDataMapper;
import edu.xhu.video.mapper.BiliVideoMapper;
import edu.xhu.video.service.BiliVideoCrudService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
@RequiredArgsConstructor
@Slf4j
public class BiliVideoCrudServiceImpl implements BiliVideoCrudService {
    private final BiliVideoMapper biliVideoMapper;

    private final BiliVideoDataMapper biliVideoDataMapper;

    /**
     * 获取全部视频id
     */
    @Override
    public ResponseResult<?> getAllVideoIds() {
        List<Long> videoIds = biliVideoMapper.getAllVideoIds();

        //判空逻辑
        if (videoIds == null)
            videoIds = new ArrayList<>();

        return ResponseResult.okResult(videoIds);
    }

    /**
     * 根据ids更新视频弹幕数
     */
    @Override
    public ResponseResult<?> updateDanmuByVideoIds(List<Long> videoIds) {
        int c = biliVideoDataMapper.updateDanmuByIds(videoIds, new Date());
        if (c < 1) {
            return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR, "更新失败~");
        }
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
}
